package com.zy.untils;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import javax.inject.Inject;

public class AppExecutors {
    private Executor diskIO;
    private Executor networkIO;
    private Executor mainThread;
    @Inject
    public AppExecutors() {
        diskIO= Executors.newSingleThreadExecutor();
        networkIO=    Executors.newFixedThreadPool(5);
        Handler handler = new Handler(Looper.getMainLooper());
        mainThread= new MainThreadExecutor();
    }

    Executor diskIO() {
        return diskIO;
    }

    Executor networkIO() {
        return networkIO;
    }

    public Executor mainThread() {
        return mainThread;
    }
    private class MainThreadExecutor implements Executor {
        private Handler mainThreadHandler = new Handler(Looper.getMainLooper());

        @Override
        public void execute(Runnable runnable) {
            mainThreadHandler.post(runnable);
        }
    }
}
